; TestController must be restarted before any changes in this file will be used.
; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html


#metadef
#author TheDefpom http://www.TheDefpom.com
#idString Siglent Technologies,SPD1168X,
#name Siglent SPD1168X
#handle SPD1168X
#replaceText MaxVoltage 16
#replaceText MaxCurrent 8


#metadef
#author TheDefpom http://www.TheDefpom.com
#idString Siglent Technologies,SPD1305X,
#name Siglent SPD1305X
#handle SPD1305X
#replaceText MaxVoltage 30
#replaceText MaxCurrent 5


#meta
#author TheDefpom http://www.TheDefpom.com
#idString Siglent Technologies,SPD1xxxX,
#name Siglent SPD1xxxX
#handle SPD1xxxX
#replaceText MaxVoltage 16
#replaceText MaxCurrent 8


#port 5025
; port 9009 is used by EasyPower but TC fails to connect on that port
; Alternate port types: comnobaud or com, com lets the user define baudrate on the "Load devices" page
;#driver SCPIx



;***********************************************************************************
; Rev 1.1 Released 8th January 2022
; Written by Scott - TheDefpom 
; Website: http://www.TheDefpom.com 
; Electronics Repair Videos: https://www.youtube.com/TheDefpom
;***********************************************************************************
; Please add any notes about 3rd party changes or future definition updates below:
; 1.0 1st January 2022 - initial release - known issue with inability to remotely control the output or the sense.
; 1.1 8th January 2022 - added a work around for a firmware bug for EOL character usage.
;
;
;
;
;
;***********************************************************************************



#notes 
Rev 1.1 Released 8th January 2022
Written by Scott - TheDefpom
Website: http://www.TheDefpom.com 
Electronics Repair Videos: https://www.youtube.com/TheDefpom

Currently only tested with the SPD11168X, but it should also work with the SPD1305X too.

There is a known firmware issue where the power supply does not always accept a "\n" termination (specifically the commands to turn on and off the output, or to switch between 2 wire (internal sense) and 4 wire (external sense) modes).

As a result this definition file is configured to not send any End Of Line Termination character to work around the firmware bug in firmware versions 2.1.1.8 and earlier, ifthese controls break in a later firmware version, then comment out the #eol line.


; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
;
#value Voltage V D3
#value Current A D3
#value Power W D3


; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this string is used.
; Number of returned values must match number of columns defined with #value
; This is a single line command
#askValues MEAS:VOLT?; MEAS:CURR?; MEAS:POWE?;
; there is also an undocumented *READALL? command that returns 48,16.000,0.000,0.000,16.000,8.000 (??,Actual V, Actual A, Actual P, Set V, Set A)


; Format of answer: f=float, u=remove trailing letters, x=skip, *=Zero upper case values if this value is 0
#askValuesReadFormat fff

; Accept this delay when reading values (seconds)
#readingDelay 2

; Mode change have a longer delay on reading values (seconds)
#modeChangeDelay 5

; String to ask about actual meter mode, it is mostly used for DMM's
; This is a single line command
#askMode SYST:STAT?

; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode

; Prepare the meter to response to #askValues
;#prepareSample arm:sour imm;:arm:count 1;:trig:sour imm;:trig:count 1;:trig:samp:count 1;init

; Initial commands to meter when establishing connection, used to disable local control
;#initCmd *LOCK

; Final command to meter before breaking connection, used to restore local control
#finalCmd *UNLOCK

; Used to turn output off for power supplies, generators and electronic loads
; THIS COMMAND DOESN'T WORK... BUG WITH THE WAY THE COMMAND IS SENT/RECEIVED BY UNIT?
;#outputOff OUTP CH1,OFF;

; Set End Of Line Termination to none... to work around firmware bug in firmware versions 2.1.1.8 and earlier.
#eol \_

; BUG TESTING
;#scpiCmd OUTPUTON txrx OUTPUT CH1,ON
;#scpiCmd OUTPUTOFF txrx OUTPUT CH1,OFF


; ********** Power Supply Setup ********

#interfaceType PS

#interface setVoltage VOLT (value)
#interface setCurrent CURR (value)

#interface getVoltage MEAS:VOLT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")
#interface getCurrent MEAS:CURR?
:readmath: getMatch(value, "( |^)[-+.0-9].*")
#interface getPower MEAS:POWE?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface readVoltage 0
#interface readCurrent 1
#interface readPower 2





;********************************************************
; Create the SETUP window and functions
;********************************************************

; *********** Voltage and Current SET points ************

#cmdSetup number Set_Voltage Setup
:read: VOLT?
:write: VOLT
:updatemodechange:
V  0 MaxVoltage

#cmdSetup number Set_Current Setup
:read: CURR?
:write: CURR
:updatemodechange:
A  0 MaxCurrent



;********************************************************
; Buttons to turn features On/Off
;********************************************************
;
; SCPI command SYST:STAT? returns the hex value of a 8-bit word.
; bit 0 indicates CV or CC mode.
; bit 4 indicates the Output State (OFF or ON).
; bit 5 indicates the 2W or 4W mode.
; bit 6 indicates the Timer OFF or TIMER ON mode.
; bit 8 indicates the Digital Display or Waveform Display mode.


#cmdSetup buttonsOn Output_Enable
:read: SYST:STAT?
:readmath: (binConvBit(value,4,1) == "1") ? "ON" : "OFF"
:string:
:write:OUTP CH1,#
;:write:#
:updatemodechange:
:tip: Turn output ON or OFF
:color: (255,0,0)
OFF OFF
ON ON
;OFF OUTPUTOFF
;ON OUTPUTON


#cmdSetup buttonsOn External_Sense
:read: SYST:STAT?
:readmath: (binConvBit(value,5,1) == "1") ? "4W" : "2W"
:string:
:write:MODE:SET #
:update: Output_Enable
:updatemodechange:
:tip: Turn external sense ON or OFF
:color: (255,0,0)
OFF 2W
ON 4W


#cmdSetup buttons Interface_Lock
:write: 
:tip: Turn interface lock ON or OFF
OFF *UNLOCK
ON *LOCK



